package com.travelingsalesmen.post;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Set;

/**
 * The product catalog contains product specifications which can be referenced by UPC codes
 */
public class Catalog implements Serializable {
	
    private static HashMap<String, ProductSpec> productMap = new HashMap<String, ProductSpec>();
    
    /**
     * Add product to the catalog
     * @param upc UPC code of the product
     * @param spec Specification or the product
     */
    public void add(String upc, ProductSpec spec) {
        productMap.put(upc, spec);
    }
    
    /**
     * 
     * @return Returns the productMap so that a the drop down on the
     * POST can be populated with UPCs
     */
    public HashMap<String, ProductSpec> getProductMap() {
        return productMap;
    }

    /**
     * Retrieve a product specification from the catalog
     * @param upc UPC code for which to retrieve the product specification
     * @return null if invalid UPC, otherwise returns the product specification
     */
    public ProductSpec getSpec(String upc) {
        ProductSpec spec = productMap.get(upc);        
    	return spec;
    }
    
    /**
     * @return A set of all UPCs in the catalog
     */
    public Set<String> getUpcs() {
        return productMap.keySet();
    }
}
